package ducna.android.aoeclip.screen.category.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import ducna.android.aoeclip.R;
import ducna.android.aoeclip.common.model.entity.Article;

/**
 * Created by DUCNA on 11/7/2014.
 * adapter of list video in 1 category
 */
public class ArticleListAdapter extends RecyclerView.Adapter<ArticleListAdapter.ViewHolder>{
    private ArrayList<Article> dataArticles;
    private int rowLayout;
    private Context context;

    public ArticleListAdapter(ArrayList<Article> dataArticles, int rowLayout, Context context){
        this.dataArticles = dataArticles;
        this.rowLayout = rowLayout;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View rowView = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(rowView);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        Article article = dataArticles.get(i);
        viewHolder.textViewTitleVideo.setText(article.getName());
        Glide.with(context).load(article.getImage()).centerCrop().placeholder(R.drawable.ic_launcher).into(viewHolder.imageViewThumbnail);

    }

    @Override
    public int getItemCount() {
        return dataArticles == null ? 0 : dataArticles.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public ImageView imageViewThumbnail;
        public TextView textViewTitleVideo;
        public ViewHolder(View itemView) {
            super(itemView);
            imageViewThumbnail = (ImageView) itemView.findViewById(R.id.imageViewVideo);
            textViewTitleVideo = (TextView) itemView.findViewById(R.id.textViewTitleVideo);
        }
    }
}
